﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000372 RID: 882
	internal class ZipLatestObservable<T1, T2, T3, T4, T5, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x060011FE RID: 4606 RVA: 0x00052528 File Offset: 0x00050928
		public ZipLatestObservable(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, ZipLatestFunc<T1, T2, T3, T4, T5, TR> resultSelector) : base(source1.IsRequiredSubscribeOnCurrentThread<T1>() || source2.IsRequiredSubscribeOnCurrentThread<T2>() || source3.IsRequiredSubscribeOnCurrentThread<T3>() || source4.IsRequiredSubscribeOnCurrentThread<T4>() || source5.IsRequiredSubscribeOnCurrentThread<T5>())
		{
			this.source1 = source1;
			this.source2 = source2;
			this.source3 = source3;
			this.source4 = source4;
			this.source5 = source5;
			this.resultSelector = resultSelector;
		}

		// Token: 0x060011FF RID: 4607 RVA: 0x000525A5 File Offset: 0x000509A5
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return new ZipLatestObservable<T1, T2, T3, T4, T5, TR>.ZipLatest(5, this, observer, cancel).Run();
		}

		// Token: 0x04000AC1 RID: 2753
		private IObservable<T1> source1;

		// Token: 0x04000AC2 RID: 2754
		private IObservable<T2> source2;

		// Token: 0x04000AC3 RID: 2755
		private IObservable<T3> source3;

		// Token: 0x04000AC4 RID: 2756
		private IObservable<T4> source4;

		// Token: 0x04000AC5 RID: 2757
		private IObservable<T5> source5;

		// Token: 0x04000AC6 RID: 2758
		private ZipLatestFunc<T1, T2, T3, T4, T5, TR> resultSelector;

		// Token: 0x02000373 RID: 883
		private class ZipLatest : NthZipLatestObserverBase<TR>
		{
			// Token: 0x06001200 RID: 4608 RVA: 0x000525B5 File Offset: 0x000509B5
			public ZipLatest(int length, ZipLatestObservable<T1, T2, T3, T4, T5, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(length, observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x06001201 RID: 4609 RVA: 0x000525D4 File Offset: 0x000509D4
			public IDisposable Run()
			{
				this.c1 = new ZipLatestObserver<T1>(this.gate, this, 0);
				this.c2 = new ZipLatestObserver<T2>(this.gate, this, 1);
				this.c3 = new ZipLatestObserver<T3>(this.gate, this, 2);
				this.c4 = new ZipLatestObserver<T4>(this.gate, this, 3);
				this.c5 = new ZipLatestObserver<T5>(this.gate, this, 4);
				//IDisposable disposable = this.parent.source1.Subscribe(this.c1);
				//IDisposable disposable2 = this.parent.source2.Subscribe(this.c2);
				//IDisposable disposable3 = this.parent.source3.Subscribe(this.c3);
				//IDisposable disposable4 = this.parent.source4.Subscribe(this.c4);
				//IDisposable disposable5 = this.parent.source5.Subscribe(this.c5);
				return StableCompositeDisposable.Create(new IDisposable[]
				{
					//disposable,
					//disposable2,
					//disposable3,
					//disposable4,
					//disposable5
				});
			}

			// Token: 0x06001202 RID: 4610 RVA: 0x000526D4 File Offset: 0x00050AD4
			public override TR GetResult()
			{
				return this.parent.resultSelector(this.c1.Value, this.c2.Value, this.c3.Value, this.c4.Value, this.c5.Value);
			}

			// Token: 0x06001203 RID: 4611 RVA: 0x00052728 File Offset: 0x00050B28
			public override void OnNext(TR value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x06001204 RID: 4612 RVA: 0x00052738 File Offset: 0x00050B38
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06001205 RID: 4613 RVA: 0x00052770 File Offset: 0x00050B70
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000AC7 RID: 2759
			private readonly ZipLatestObservable<T1, T2, T3, T4, T5, TR> parent;

			// Token: 0x04000AC8 RID: 2760
			private readonly object gate = new object();

			// Token: 0x04000AC9 RID: 2761
			private ZipLatestObserver<T1> c1;

			// Token: 0x04000ACA RID: 2762
			private ZipLatestObserver<T2> c2;

			// Token: 0x04000ACB RID: 2763
			private ZipLatestObserver<T3> c3;

			// Token: 0x04000ACC RID: 2764
			private ZipLatestObserver<T4> c4;

			// Token: 0x04000ACD RID: 2765
			private ZipLatestObserver<T5> c5;
		}
	}
}
